#parse argument

architecture=$1
matrix_decompressed_file=$2
matrix_comp_file=$3
output_dir=$4
lorem_ipsum_file=$5

permutation_str=""

# make hash

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --sequence-conf -xmatrix $matrix_decompressed_file \
    --permutation-conf -arch $architecture $permutation_str \
    --make-hash -plain-text $lorem_ipsum_file -hash $output_dir/hash.xf
"
echo ""; echo $str; echo ""
eval $str

# check hash

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -hash $output_dir/hash.xf \
    --sequence-conf -xmatrix $matrix_decompressed_file \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/lib_info_log_file.xf \
    --check-hash -plain-text $lorem_ipsum_file
"
echo ""; echo $str; echo ""
eval $str

str=" 
if ! [ -s $output_dir/lib_info_log_file.xf ]; then echo FAIL ; exit ; fi ; \
if grep -q FAIL \"$output_dir/lib_info_log_file.xf\" ; then echo FAIL ; exit ; fi
"
echo ""; echo $str; echo ""
eval $str

# generate wrong file

str=" 
cp $lorem_ipsum_file $output_dir/wrong_lorem_ipsum ; echo "a" >> $output_dir/wrong_lorem_ipsum ;
"
echo ""; echo $str; echo ""
eval $str

# check hash

str="
xrnlib-cli \
    --decoding-conf -compiled-param -no-password \
    --encoding-conf -compiled-param -no-password \
    --arithmetic-conf -hash $output_dir/hash.xf \
    --sequence-conf -xmatrix $matrix_decompressed_file \
    --permutation-conf -arch $architecture \
    --logging-conf -lib-info-log $output_dir/wrong_lib_info_log_file.xf \
    --check-hash -plain-text $output_dir/wrong_lorem_ipsum 
"
echo ""; echo $str; echo ""
eval $str

str=" 
if ! [ -s $output_dir/wrong_lib_info_log_file.xf ]; then echo FAIL ; exit ; fi ; \
if grep -q PASS \"$output_dir/wrong_lib_info_log_file.xf\" ; then echo FAIL ; exit ; fi
"
echo ""; echo $str; echo ""
eval $str



